﻿using System;
using SchemaGen.Xsd;

namespace SchemaGen.Attributes
{
    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Class, Inherited = true, AllowMultiple = true)]
    public class XmlNumericTypeAttribute : XmlSimpleTypeAttribute
    {
        public object Minimum { get; set; }
        public object Maximum { get; set; }
        public Type BaseType { get; set; }
        public int FractionDigits { get; set; }
        public int TotalDigits { get; set; }
        public bool ExclusiveMinMax { get; set; }

        private SSimpleType _Restriction;
        public override SSimpleType Restriction
        {
            get
            {
                if (_Restriction == null)
                {
                    _Restriction = SSimpleType.GetNumericRestriction(Minimum, Maximum, BaseType, FractionDigits, TotalDigits, ExclusiveMinMax);
                    _Restriction.Name = Name;
                    _Restriction.Documentation = Documentation;
                };

                return _Restriction;
            }
        }

        public XmlNumericTypeAttribute(string name)
            : base(name)
        {
            FractionDigits = -1;
        }
    }
}
